<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">储位id</label>
        <el-input v-model="query.storageId" clearable placeholder="储位id" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">储位区域</label>
        <el-input v-model="query.storageArea" clearable placeholder="储位区域" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">储位线体</label>
        <el-input v-model="query.storageLine" clearable placeholder="储位线体" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">储位站点</label>
        <el-input v-model="query.storagePoint" clearable placeholder="储位站点" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">对应储位描述</label>
        <el-input v-model="query.storageDescription" clearable placeholder="对应储位描述" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" :upload="true" :url="uploadUrl" :plain="true" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="120px">
          <el-form-item label="储位id">
            <el-input v-model="form.storageId" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="储位描述">
            <el-input v-model="form.storageDescription" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="储位区域">
            <!-- <el-input v-model="form.storageArea" style="width: 250px;" /> -->
            <el-select v-model="form.storageArea" allow-create clearable style="width: 250px;" filterable placeholder="请选择">
              <el-option
                v-for="item in storageAreaList"
                :key="item.value"
                :label="item.value"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="储位线体">
            <!-- <el-input v-model="form.storageLine" style="width: 250px;" /> -->
            <el-select v-model="form.storageLine" allow-create clearable style="width: 250px;" filterable placeholder="请选择">
              <el-option
                v-for="item in storageLineList"
                :key="item.value"
                :label="item.value"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="储位站点">
            <el-input v-model="form.storagePoint" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="储位类型">
            <!-- <el-input v-model="form.storageType" style="width: 250px;" /> -->
            <el-select v-model="form.storageType" allow-create clearable style="width: 250px;" filterable placeholder="请选择">
              <el-option
                v-for="item in storageTypeList"
                :key="item.value"
                :label="item.value"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <!-- <el-form-item label="锁定情况">
            <el-select v-model="form.lockStatus" style="width: 250px;" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.lock_status"
                :key="item.id"
                :label="item.label"
                :value="Number(item.value)"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="占用情况">
            <el-select v-model="form.takeStatus" style="width: 250px;" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.take_status"
                :key="item.id"
                :label="item.label"
                :value="Number(item.value)"
              />
            </el-select>
          </el-form-item> -->
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <!-- <el-table-column type="selection" width="55" /> -->
        <el-table-column prop="storageId" label="储位id" />
        <el-table-column prop="storageArea" label="储位区域" />
        <el-table-column prop="storageLine" label="储位线体" />
        <el-table-column prop="storagePoint" label="储位站点" />
        <el-table-column prop="storageDescription" label="对应储位描述" />
        <el-table-column label="锁定情况">
          <template slot-scope="scope">
            {{ dict.label.lock_status[scope.row.lockStatus] }}
          </template>
        </el-table-column>
        <el-table-column label="占用情况">
          <template slot-scope="scope">
            {{ dict.label.take_status[scope.row.takeStatus] }}
          </template>
        </el-table-column>
        <!-- <el-table-column prop="createBy" label="创建人" /> -->
        <!-- <el-table-column prop="updateBy" label="更新人" /> -->
        <el-table-column prop="createTime" label="创建时间" />
        <!-- <el-table-column prop="updateTime" label="更新时间" /> -->
        <el-table-column v-if="checkPer(['admin','wcsStorage:edit','wcsStorage:del'])" label="操作" width="180px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudWcsStorage from '@/api/work/storageMaintenance'
import { getContainerTypeAPI } from '@/api/work/storageMaintenance'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { id: null, storageId: null, storageArea: null, storageLine: null, storagePoint: null, storageType: null, storageDescription: null, lockStatus: null, takeStatus: null, extra: null, version: null, createBy: null, updateBy: null, createTime: null, updateTime: null }
export default {
  name: 'StorageMaintenance',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['lock_status', 'take_status'],
  cruds() {
    return CRUD({ title: '储位', url: 'api/wcsStorage', idField: 'id', sort: 'id,desc', crudMethod: { ...crudWcsStorage },
      optShow: {
        add: true,
        edit: false,
        del: true,
        download: true,
        reset: true
      }
    })
  },
  data() {
    return {
      permission: {
        add: ['admin', 'wcsStorage:add'],
        edit: ['admin', 'wcsStorage:edit'],
        del: ['admin', 'wcsStorage:del']
      },
      rules: {
      },
      queryTypeOptions: [
        { key: 'storageId', display_name: '储位id' },
        { key: 'storageArea', display_name: '储位区域，excel为区域' },
        { key: 'storageLine', display_name: '储位线体，excel为线体' },
        { key: 'storagePoint', display_name: '储位站点，excel站点' },
        { key: 'storageDescription', display_name: '对应储位描述，excel为编号' }
      ],
      uploadUrl: '/api/wcsStorage/importStorageInfo',
      storageAreaList: [],
      storageLineList: [],
      storageTypeList: []
    }
  },
  watch: {
    'crud.status.add'(newVal) {
      // console.log(newVal)
      if (newVal === 1) {
        this.getContainerType()
      } else {
        this.storageAreaList = []
        this.storageLineList = []
        this.storageTypeList = []
      }
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    async getContainerType() {
      const res = await getContainerTypeAPI()
      // console.log(res)
      this.storageTypeList = res.data.storageType.map(item => {
        return {
          value: item
        }
      })
      this.storageAreaList = res.data.storageArea.map(item => {
        return {
          value: item
        }
      })
      this.storageLineList = res.data.storageLine.map(item => {
        return {
          value: item
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
